/**
 * 
 */
package org.shortestpath.core;

import org.shortestpath.service.DbService;
import java.sql.SQLException;
import java.util.Vector;


/**
 * @author Thilani
 *
 */
public class Main {

    DbService dbService = new DbService();

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Main main = new Main();
		main.performDijkrast();		
	}
	
	/**
	 * Performs the Dijkrast algorithm
	 */
	public void performDijkrast(){
	    Dijkstrast dijkstrast = new Dijkstrast();
		try {
			Vector<org.shortestpath.core.Point> points = dbService.getAllPoints();
			//iterates the points vector and sets the adjacent vertex
			for (int i=0; i<points.size(); i++){
			    Point point  = points.get(i);
			    setAdjVertexes(point, points);
			}
			Vector<Point> resultGraph  = dijkstrast.calculateShortestPath(points.elementAt(3),points.elementAt(7), points);
			System.out.println(resultGraph.elements().toString());
									
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/**
	 * Set the adjacent vertexes.
	 * 
	 * @param vertex
	 */
	public void setAdjVertexes(org.shortestpath.core.Point vertex, Vector<org.shortestpath.core.Point> vertexes){
	    String adj_nodes = vertex.getAdj_Nodes();
	    String[] adjacent_nodes = adj_nodes.split(",");
	    //sets the adjacent vertexes for the point
        for (int i=0; i< adjacent_nodes.length; i++){
            String adjacent_node = adjacent_nodes[i];
            if (!adjacent_node.equals("-1")){
                int gid = Integer.parseInt(adjacent_node);
                vertex.addAdjacentNodes(vertexes.elementAt(gid));
            }
        }
        
	    
	}

}
